package com.example.controller;

import com.example.result.Result;
import com.example.entity.Logistics;
import com.example.service.LogisticsService;
import com.example.vo.LogisticsVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/logistics")
@Tag(name = "物流相关接口",description = "物流模块的描述")
public class LogisticsController {

    @Autowired
    private LogisticsService logisticsService;

    /**
     * 卖家为生成的订单填写物流信息,订单编号，物流公司（顺丰、圆通...），物流编号
     */
    @PostMapping("/add")
    @Operation(summary = "新增物流",description="卖家为生成的订单填写物流信息")
    public Result addLogistics(@RequestBody Logistics logistics){
        logisticsService.addLogistics(logistics);
        return Result.success();
    }
    //商品准备中 待发货 已发货 派件中
    //批量更新物流状态

    /**
     * 批量修改商订单物流状态
     * @param logisticsList
     * @return
     */
    @PostMapping("/update/{sId}")
    @Operation(summary = "更新物流",description="卖家为生成的订单更新物流信息")
    public Result updateLogistics(@RequestBody List<Logistics> logisticsList,@RequestParam int logisticsStatus,@PathVariable int sId){
        return logisticsService.updateLogistics(logisticsList,logisticsStatus,sId);
    }


    /**
     * 买家根据订单id查询物流信息，查到订单物流公司、物流编号、物流状态
     */
    @GetMapping("/getlogistics/{orderId}")
    @Operation(summary = "查询物流信息",description="买家根据订单id查询物流信息")
    public Result<Logistics> getLogistics(@PathVariable Integer orderId){
        Logistics logistics=new Logistics();
        logistics=logisticsService.getLogistics(orderId);
        return Result.success(logistics);
    }

    @GetMapping("/getLogisticsBySid/{sId}")
    @Operation(summary = "商家查询店铺的订单物流信息",description="商家查询自己店铺的订单物流信息")
    public Result<List<LogisticsVO>> getLogisticsBySid(@PathVariable Integer sId){
        return logisticsService.getLogisticsBySid(sId);
    }
}
